// 工作流定义模型
export interface WorkflowDefinition {
  id: string
  name: string
  description: string
  version: string
  createdAt: Date
  isActive: boolean
  steps: WorkflowStep[]
}

// 工作流步骤模型
export interface WorkflowStep {
  id: string
  name: string
  type: string // Approval, Parallel, Condition, etc.
  order: number
  approvers: string[] // 审批人ID列表
  ccUsers: string[] // 抄送人ID列表
  condition?: string // 条件表达式
  properties: Record<string, any> // 额外属性
  position?: { x: number; y: number }
  // Workflow-Core 特定属性
  workflowStepType?: string // 对应的 Workflow-Core 步骤类型
  stepId?: string // 步骤ID
}

// 工作流实例模型
export interface WorkflowInstance {
  id: string
  definitionId: string
  status: 'Running' | 'Completed' | 'Suspended' | 'Terminated'
  createdAt: Date
  completedAt?: Date
  createdBy: string
  data: Record<string, any>
}

// 工作流任务模型
export interface WorkflowTask {
  id: string
  instanceId: string
  stepId: string
  assignee: string
  status: 'Pending' | 'Approved' | 'Rejected' | 'Delegated' | 'AddSigned'
  createdAt: Date
  completedAt?: Date
  comment?: string
  action?: 'Approve' | 'Reject' | 'Delegate' | 'AddSign'
}

// API请求模型
export interface CreateWorkflowRequest {
  name: string
  description: string
  steps: WorkflowStep[]
}

export interface StartWorkflowRequest {
  definitionId: string
  data: Record<string, any>
}

export interface ApproveTaskRequest {
  taskId: string
  comment?: string
  action: 'Approve' | 'Reject' | 'Delegate' | 'AddSign'
  delegateTo?: string // 委托给谁
  addSignUsers?: string[] // 加签用户列表
}

// 用户和组织模型
export interface User {
  id: string
  name: string
  email: string
  departmentId: string
  roles: string[]
}

export interface Department {
  id: string
  name: string
  managerId: string
}

export interface Role {
  id: string
  name: string
  code: string
  description?: string
}

// 流程设计器节点数据
export interface FlowNode {
  id: string
  type?: string
  position: { x: number; y: number }
  data: {
    name: string
    type: string
    approvers?: User[]
    ccUsers?: User[]
    condition?: string
    properties?: Record<string, any>
    jointRule?: 'all' | 'any' | 'majority'
    addType?: 'before' | 'after'
    rejectTarget?: { id: string; name: string; type: string }
    // 并行节点属性
    parallelRule?: 'all' | 'any' | 'majority'
    parallelBranches?: ParallelBranch[]
    // 等待节点属性
    waitTime?: string
    waitType?: 'fixed' | 'dynamic' | 'event'
    // 脚本节点属性
    scriptType?: 'javascript' | 'python' | 'shell' | 'sql'
    scriptContent?: string
    timeout?: number
    errorHandling?: 'continue' | 'stop' | 'retry'
    // 邮件节点属性
    emailSubject?: string
    emailRecipients?: string
    emailBody?: string
    // 定时器节点属性
    timerSchedule?: string
    timerType?: 'cron' | 'interval' | 'delay'
    // Webhook节点属性
    webhookUrl?: string
    webhookMethod?: string
    webhookHeaders?: Record<string, string>
    webhookBody?: string
    // 通知节点属性
    notificationType?: 'sms' | 'push' | 'inapp'
    notificationMessage?: string
    notificationRecipients?: string[]
    // 子流程节点属性
    subprocessId?: string
    subprocessParameters?: Record<string, any>
  }
}

// 并行分支
export interface ParallelBranch {
  name: string
  steps: WorkflowStep[]
}

// 高级工作流步骤类型
export interface AdvancedWorkflowStep extends WorkflowStep {
  // 并行步骤
  parallelRule?: 'all' | 'any' | 'majority'
  parallelBranches?: ParallelBranch[]
  
  // 等待步骤
  waitTime?: string
  waitType?: 'fixed' | 'dynamic' | 'event'
  
  // 脚本步骤
  scriptType?: 'javascript' | 'python' | 'shell' | 'sql'
  scriptContent?: string
  timeout?: number
  errorHandling?: 'continue' | 'stop' | 'retry'
  
  // 邮件步骤
  emailSubject?: string
  emailRecipients?: string[]
  emailBody?: string
  emailCcRecipients?: string[]
  
  // 定时器步骤
  timerSchedule?: string
  timerType?: 'cron' | 'interval' | 'delay'
  
  // Webhook步骤
  webhookUrl?: string
  webhookMethod?: string
  webhookHeaders?: Record<string, string>
  webhookBody?: string
  
  // 通知步骤
  notificationType?: 'sms' | 'push' | 'inapp'
  notificationMessage?: string
  notificationRecipients?: string[]
  
  // 子流程步骤
  subprocessId?: string
  subprocessParameters?: Record<string, any>
}

// 流程设计器边数据
export interface FlowEdge {
  id: string
  source: string
  target: string
  type?: string
  data?: Record<string, any>
}

// 流程元素（节点或边）
export type FlowElement = FlowNode | FlowEdge

// Workflow-Core 工作流数据
export interface WorkflowCoreData {
  instanceId: string
  currentStep: string
  approvers: string[]
  ccUsers: string[]
  needsManagerApproval: boolean
  condition: string
  properties: Record<string, any>
}

// 工作流步骤类型枚举
export enum WorkflowStepType {
  Start = 'start',
  Approval = 'approval',
  JointApproval = 'joint-approval',
  AddApproval = 'add-approval',
  Reject = 'reject',
  Condition = 'condition',
  Parallel = 'parallel',
  Wait = 'wait',
  Script = 'script',
  Email = 'email',
  Notification = 'notification',
  End = 'end'
}

// 工作流状态枚举
export enum WorkflowStatus {
  Running = 'Running',
  Completed = 'Completed',
  Suspended = 'Suspended',
  Terminated = 'Terminated'
}

// 任务状态枚举
export enum TaskStatus {
  Pending = 'Pending',
  Approved = 'Approved',
  Rejected = 'Rejected',
  Delegated = 'Delegated',
  AddSigned = 'AddSigned'
}

// 任务操作枚举
export enum TaskAction {
  Approve = 'Approve',
  Reject = 'Reject',
  Delegate = 'Delegate',
  AddSign = 'AddSign'
}

// 会签规则枚举
export enum JointRule {
  All = 'all',
  Any = 'any',
  Majority = 'majority'
}

// 加签类型枚举
export enum AddType {
  Before = 'before',
  After = 'after'
}

// API响应模型
export interface ApiResponse<T = any> {
  success: boolean
  data?: T
  message?: string
}

// 工作流定义响应
export interface WorkflowDefinitionResponse extends ApiResponse<WorkflowDefinition> {}

// 工作流实例响应
export interface WorkflowInstanceResponse extends ApiResponse<WorkflowInstance> {}

// 工作流任务响应
export interface WorkflowTaskResponse extends ApiResponse<WorkflowTask> {}

// 用户列表响应
export interface UserListResponse extends ApiResponse<User[]> {}

// 部门列表响应
export interface DepartmentListResponse extends ApiResponse<Department[]> {}

// 角色列表响应
export interface RoleListResponse extends ApiResponse<Role[]> {} 